/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.timesoft.base.rightmenubox;

import com.timesoft.zk.common.ctrl.IncludePageWsController;
import com.timesoft.zk.common.ctrl.MainPageWsController;
import com.timesoft.zk.common.event.MainEventWsListener;
import org.apache.log4j.Logger;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.A;

/**
 *
 * @author sorasaks
 */
public class SettingCtrl extends IncludePageWsController {
    
    private static final Logger LOG = Logger.getLogger(SettingCtrl.class);
    
    private A linkSetting;
    private A linkPrivacy;
    private A linkSignout;
    
    public SettingCtrl() throws Exception {
        super();
    }

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp); //To change body of generated methods, choose Tools | Templates.
        initialEventListener();
    }
    
    private void initialEventListener() throws Exception {
        linkSignout.addEventListener(Events.ON_CLICK, new linkSignoutEventListener());
    }

    private class linkSignoutEventListener extends MainEventWsListener implements EventListener {

        public linkSignoutEventListener() throws Exception {
            super();
        }

        @Override
        public void onEvent(Event t) throws Exception {
            Executions.getCurrent().getSession().setAttribute(MainPageWsController.ATTRIBUTE_CUSTOMER_CODE, null);
            Executions.getCurrent().getSession().setAttribute(MainPageWsController.ATTRIBUTE_AUTHENTIFICATION, null);
            
            Executions.sendRedirect(contextPath);
        }
    }
    
}
